package com.factory.controller;

import com.factory.domain.warnTable;
import com.factory.http.AjaxResult;
import com.factory.service.IWarnTableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import static com.factory.http.AjaxResult.success;
/**
 * 【报警信息】Controller
 */
@RestController
@RequestMapping("/system/warnTable")
public class WarnTableController {
    private String prefix = "system/warnTable";
    @Autowired
    private IWarnTableService warnTableService;
    @GetMapping()
    public String table() {
        return prefix + "/warnTable";
    }
    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    @ResponseBody
    public AjaxResult list(warnTable warnData) {
        List<warnTable> list = warnTableService.selectWarnTableList(warnData);
        return success(list);
    }
    /**
     * 新增保存【请填写功能名称】
     */
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(warnTable warnData) {
        System.out.println("增加一条数据");
        return success(warnTableService.insertWarnTable(warnData));
    }
    //根据系统查询报警信息
    @GetMapping("/getPolicePage")
    public AjaxResult getListPage(Long systemId, Long page) {
        if (page != null) {
            Long startPage = (page - 1) * 20;
            Long endPage = page * 20;
            List<warnTable> warnListData = warnTableService.getPolicePage(systemId, startPage, endPage);
            for (int i = 0; i < warnListData.size(); i++) {
                warnListData.get(i).setId(((page - 1) * 20) + (i + 1));
            }
            return success(warnListData);
        }
        return null;
    }
}
